package com.boot.service.impl;

import com.boot.bean.UserDo;
import com.boot.repository.UserRepository;
import com.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;


    @Override
    public UserDo login(String username, String password){
        UserDo user = new UserDo();
        user.setLoginName(username);
        user.setPassword(password);

        Example<UserDo> example = Example.of(user);
        Optional<UserDo> one = userRepository.findOne(example);
        return  one.get();
    }

    @Override
    public UserDo save(UserDo userDo) {
        return userRepository.save(userDo);
    }
    @Override
    public UserDo getOne(Long id) {
        Optional<UserDo> byId = userRepository.findById(id);
        return byId.get();
    }
}
